package Randomstudent;

import java.util.ArrayList;
import java.util.Random;

public class CallName<fori> {
    /*
    创建集合 存储学生类
    浏览所有信息
    随机选取一个学生
     */
    public static void main(String[] args){
        ArrayList<RandomStudent> array=new ArrayList<RandomStudent>();
        addStudent(array);
        printStuden(array);
        randomStudent(array);
    }
    /*
    随机生成一个数字
    点到不同的学生
     */
    public static void randomStudent(ArrayList<RandomStudent> array){
        Random r = new Random();
        int num = r.nextInt(2);
        RandomStudent ran = array.get(num);
        System.out.println("随机点到的学生是"+ran.getName()+"  "+ran.getAge());
    }
//    Random r = new Random();
//    int num = r.nextInt(2);
//    RandomStudent ran=(RandomStudent)array.get(num);
//    System.out.println("随机点到的学生是"+ran.getName()+"  "+ran.getAge());
    /*
    遍历数组
    浏览全部学生
     */
    public static void printStuden(ArrayList<RandomStudent> array){
        for (int i = 0; i <array.size() ; i++) {
            RandomStudent aim = (RandomStudent)array.get(i);
            System.out.println(aim.getName()+"  "+aim.getAge());
        }
    }
//    for(int i=0;i<array.size();i++){
//        RandomStudent aim = (RandomStudent)array.get(i);
//        System.out.println(aim.getName()+"  "+aim.getAge());
//
//    }
    /*
    存储学生信息
     */
    public static void addStudent(ArrayList<RandomStudent> array){
        RandomStudent student = new RandomStudent(12,"tom");
        RandomStudent student2 = new RandomStudent(12,"tom6");
        RandomStudent student3= new RandomStudent(12,"tom8");
        array.add(student);
        array.add(student2);
        array.add(student3);
    }
//    RandomStudent student = new RandomStudent(age:12,:name"tom");
//    array.add(student);

}
